#include "SeqList.h"
void SLInit(SL* ps)
{
	ps->arr = NULL;
	ps->capacity = ps->size = 0;
}
void SLDestroy(SL*ps)
{
	if (ps->arr)
	{
		free(ps->arr);
	}
	ps->arr = NULL;
	ps->size = ps->capacity = 0;
}
void SLCheckCapacity(SL* ps)
{
	if (ps->capacity == ps->size)
	{
		int newCapacity = ps->capacity == 0 ? 4: 2 * ps->size;
		SLDataType* temp = (SLDataType*)realloc(ps->arr, ps->capacity * 2 * sizeof(SLDataType));
		if (temp == NULL)
		{
			perror("realloc fail");
			return 1;
		}
		ps->arr = temp;
		ps->capacity = newCapacity;
	}
}
void SLPushfront(SL* ps, SLDataType x)
{
	assert(ps);
	SLCheckCapacity(ps);
	for (int i = ps->size; i > 0; i--)
	{
		ps->arr[i] = ps->arr[i - 1];
	}
	ps->arr[0] = x;
	ps->size++;
}
void SLPopback(SL* ps)
{
	assert(ps);
	ps->size--;
}
void SLPopFront(SL* ps)
{
	assert(ps);
	assert(ps->size);
	for (int i = 0; i < ps->size - 1; i++)
	{
		ps->arr[i] = ps->arr[i + 1];
	}
	ps->size--;

}
void SLPushBack(SL* ps, SLDataType x)
{
	if (ps == NULL)
		return 1;
	SLCheckCapacity(ps);
	ps->arr[ps->size++] = x;
}
